<?php
App::uses('AppController', 'Controller');
App::uses('Sanitize', 'Utility');

class UsersController extends AppController {

	var $name ="Users";
	public $helpers = array('Date', 'Datefr', 'Moninput', 'Session_gpp');


	function login(){
		if ($this->request->is('post')) {
	        if ($this->Auth->login()) {
	            return $this->redirect($this->Auth->redirect());
	        } else {
	            $this->Session->setFlash(__('Username or password is incorrect'), 'default', array(), 'auth');
	        }
	    }
	}

	function logout(){
		$this->redirect($this->Auth->logout());
	}

 	function add(){
 		$data=array();
 		$data['User']['username']='lebretr';
 		$data['User']['password']='lebretr';
 		$this->User->save($data);
 	}

 	function view($id){
		$id = Sanitize::paranoid($id);
		$id = Sanitize::clean($id, array('encode' => false, 'unicode'=> true));

 		$this->User->id = $id;
		if (!$this->User->exists()) {
			throw new NotFoundException(__('Invalid user'));
		}

		$this->set('user', $this->User->read(null, $id));
		$this->request->data = $this->User->read(null, $id);
 	}
}